package com.wy.timer;

/**
 * @author 美女
 * @date 2022/05/02 17:57
 **/
public class ImplTimer1 {
    static class MyThread extends Thread{
        //线程执行我们分配给它的任务
        Runnable task;
        long delay;//传入时间
        MyThread(Runnable task,long delay){
            this.task=task;
            this.delay=delay;
        }

        @Override
        public void run() {
            try {
                Thread.sleep(delay);//毫秒为单位的休眠
                task.run();//休眠之后执行任务:打印时间到了
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        Runnable task=new Runnable() {
            @Override
            public void run() {
                System.out.println("时间到了");
            }
        };
        MyThread t=new MyThread(task,5000);
        t.start();
        while (true){}
    }
}
